package nowCoder;

import java.util.Scanner;

public class HJ48 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int s = in.nextInt();
        Lian qd = new Lian(in.nextInt(), null);
        for (int i = 0; i < s - 1; i++) {
            int x = in.nextInt();
            int l = in.nextInt();
            Lian dq = new Lian(x,null);
            Lian p = qd;
            do{
                if (p.x == l){
                    Lian f = p.y;
                    p.y = dq;
                    dq.y = f;
                }
                p = p.y;
            }while (p != null);
        }
        int n = in.nextInt();
        do {
            if (qd.x != n) {
                System.out.print(qd.x+" ");
            }
            qd = qd.y;
        }while (qd != null);
    }
    static class Lian{
        int x;
        Lian y;
        public Lian(int x, Lian y){
            this.x = x;
            this.y = y;
        }
    }
}
